package cn.skcks.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/user")
public class LoginController {

	@RequestMapping("/main")
	public String main(){
		return "main";
	}

	@RequestMapping("/toLogin")
	public String toLogin(){
		return "login";
	}

	@RequestMapping(value = "/login")
	public String login(HttpSession session, String user, String password){
		if(user.equals("shikong")){
			if (password.equals("12341234")){
				// 将用户信息存储在 Session 中
				session.setAttribute("user","shikong");
				return "redirect:/user/main";
			}
		}
		return "login";
	}

	@RequestMapping(value = "logout")
	public String toLogout(HttpSession session){

		session.removeAttribute("user");

		return "redirect:/user/main";
	}
}